package com.example.demo.config;

import com.example.demo.common.Appvar;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:  自定义拦截器  1.实现接口HandlerInterceptor  2.重写preHandle 方法设置返回值Boolean
 * User: yyx
 * Date: 2023-11-03
 * Time: 11:03
 */
@Component//自定义拦截器需要家注解啊!!!!!!
public class UserInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession(false);
        if(session != null && session.getAttribute(Appvar.SESSION_KEY) != null){
            return true;
        }
        return false;
    }
}
